package com.smart.campus.school.service.impl;

import com.smart.campus.common.core.text.Convert;
import com.smart.campus.common.utils.DateUtils;
import com.smart.campus.framework.util.ShiroUtils;
import com.smart.campus.school.domain.ScBadge;
import com.smart.campus.school.mapper.ScBadgeMapper;
import com.smart.campus.school.service.IScBadgeService;
import com.smart.campus.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 729002330@qq.com
 * @date :2020-05-26
 */
@Service
public class ScBadgeServiceImpl implements IScBadgeService {

    @Autowired
    private ScBadgeMapper scBadgeMapper;

    /**
     *  根据校徽Id查询
     * @param id 校徽ID
     * @return
     */
    @Override
    public ScBadge selectScBadgeById(Long id) {
       return scBadgeMapper.selectScBadgeById(id);
    }

    /**
     *  根据查询条件返回符合查询条件的数据集合
     * @param badge 校徽信息
     * @return
     */
    @Override
    public List<ScBadge> selectScBadgeList(ScBadge badge) {
        return scBadgeMapper.selectScBadgeList(badge);
    }

    /**
     *  添加新的校徽记录，同时生成校徽编号，为后续标签写入提供数据
     * @param badge 校徽信息
     * @return
     */
    @Override
    public ScBadge insertScBadge(ScBadge badge) {
        //参数1为终端ID
        //参数2为数据中心ID
        long id  = scBadgeMapper.insertScBadge(badge);
        badge.setId(id);
        return badge;
    }

    /**
     *  更新校徽信息
     * @param badge 校徽信息
     * @return
     */
    @Override
    public int updateScBadge(ScBadge badge) {
        SysUser currUser = ShiroUtils.getSysUser();
        badge.setUpdateBy(currUser.getUserName());
        badge.setUpdateTime(DateUtils.getNowDate());
        return scBadgeMapper.updateScBadge(badge);
    }

    /**
     *  删除多个校徽信息  传入的时主键字符串，用逗号分隔开来如：id,id1,id2...
     * @param ids 需要删除的数据ID
     * @return
     */
    @Override
    public int deleteScBadgeByIds(String ids) {
        return scBadgeMapper.deleteScBadgeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除校徽信息
     * @param id 校徽ID
     * @return
     */
    @Override
    public int deleteScBadgeById(Long id) {
        return scBadgeMapper.deleteScBadgeById(id);
    }
}
